
#ifndef LOD_VECTOR4_H
#define LOD_VECTOR4_H

#include "vector3.h"

template<class co_type>
class vector4 : public vector3<co_type>
{
    public:
    co_type w;

    vector4(co_type X, co_type Y, co_type Z, co_type W)
     : vector3<co_type>(X,Y,Z), w(W)
    {
    }

    vector4()
    {
    }

    //! Normalize the vector (rescales it to the length of 1 unit)
    void normalize()
    {
        co_type length = norm();
        if(length!=(co_type)0) {
            this->x /= length;
            this->y /= length;
            this->z /= length;
            this->w /= length;
        }
    }

    //! Returns the norm (~ length) of the vector
    co_type norm()
    {
        return std::sqrt(this->x * this->x + 
                        this->y * this->y + 
                        this->z * this->z + 
                        this->w * this->w);
    }

    
    /*!
     * \param n A vector to compare this vector with */
    bool operator== (const vector4<co_type> & n) const
    {
        //todo: alternative: epsilon-accurate comparison
        return w == n.w  &&  (vector3<co_type>)(*this) == n;
    }
};

#endif // LOD_VECTOR4_H
